﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Text;


namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UQuestionnaireReportPage : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "UReturnVisitReport";
            }
        }
        #region 属性 (查询条件)


        protected string CreateDateFrom
        {
            get
            {
                return GetRequestValue<string>("CreateDateFrom", DateTime.Now.ToString("yyyy-MM-01"));

            }
        }

        protected string CreateDateTo
        {
            get
            {
                return GetRequestValue<string>("CreateDateTo", DateTime.Now.ToString("yyyy-MM-dd"));
            }
        }
        protected int ParId
        {
            get
            {
                return GetRequestValue<int>("ParId", 1);
            }
        }


        protected string ReportTitle
        {
            get
            { 
                 List<UQuestionTempleteInfo> list = UWarrantyCardController.GetAllUQuestionTempleteByParId(0);

                 return string.Format("用户调查报表-【{0}】", list.Find(e => e.UQTID == ParId).Title);
            }
        }

        protected string ReportSubTitle
        {
            get
            {
                int allcount = UWarrantyCardController.GetReprotSUMCount(CreateDateFrom, CreateDateTo);

                return string.Format("共有{0}个用户接受调查", allcount);
            }
        }
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
          DataBind2();

        }


        protected void DataBind2()
        {
            rpData.DataSource = report4dts;
            rpData.DataBind();

        }

        #region 报表4.各员工工时对比
        protected void DataBind4()
        {

            //this.rp2_1.DataSource = report2dts[0];
            //this.rp2_1.DataBind();
            ////

            //foreach (DataRow dr in report2dts[1].Rows)
            //{
            //    totaltasktime += Convert.ToDecimal(dr["TaskTime"]);
            //}
            //this.rp2_2.DataSource = report2dts[1];
            //this.rp2_2.DataBind();

        }

        List<string> Report4colNames = new List<string>();
        private DataTable _report4dts = null;
        private DataTable report4dts
        {
            get
            {
                if (_report4dts == null)
                    _report4dts =  UWarrantyCardController.GetReport(ParId, CreateDateFrom, CreateDateTo);
               
                return _report4dts;
            }
        }
        /// <summary>
        /// 获取报表4 主表的X轴
        /// </summary>
        /// <returns></returns>
        protected string GetReport4JSCategories()
        {
            DataTable dtcl = report4dts;
            StringBuilder sb = new StringBuilder();
            //表头添加
            sb.Append("[");
            int rowindex = 1;
            foreach (DataRow dr in dtcl.Rows)
            {
                string RealName = dr["title"].ToString();
                if (!Report4colNames.Contains(RealName))
                {
                    sb.AppendFormat("'{0}'", RealName);
                    Report4colNames.Add(RealName);
                    if (rowindex != dtcl.Rows.Count)
                    {
                        sb.AppendFormat(",");
                    }
                }

                rowindex++;
            }
            sb.Append("]");
            string filedstr = sb.ToString();
            return filedstr;
        }

        protected string GetReport4JSSeries()
        {
            /*
             [{
                    name: 'John',
                    data: [5, 3, 4, 7, 2]
                }, {
                    name: 'Jane',
                    data: [2, 2, 3, 2, 1]
                }, {
                    name: 'Joe',
                    data: [3, 4, 4, 2, 5]
                }]
             */
            DataTable dtmain = report4dts;
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("[");



            string str直接 = "{name: '项目百分比',data:[";
            int rowindex = 1;
            foreach (DataRow colName in dtmain.Rows)
            {

                string TaskTime = Convert.ToDecimal(colName["num"]).ToString("f2");
                str直接 += TaskTime;
                if (rowindex != Report4colNames.Count)
                {
                    str直接 += ",";
                }
                rowindex++;
            }
            str直接 += "]}";


            sb.AppendLine(str直接);



            sb.AppendLine("]");
            return sb.ToString();
        }
        #endregion
    }
}